# 构建阶段
FROM maven:3.8.8-eclipse-temurin-8 AS builder
WORKDIR /build

# 复制 pom.xml 并下载依赖
COPY pom.xml .

# 在构建前需要将服务器的 settings.xml 复制到项目根目录命名为 settings.xml
COPY settings.xml /root/.m2/settings.xml

RUN mvn dependency:go-offline -B

# 复制源代码
COPY src ./src

# 构建应用（使用 Maven settings.xml 中的属性）
RUN mvn clean package -DskipTests -B

# 运行阶段
FROM eclipse-temurin:8-jre-alpine
WORKDIR /app
COPY --from=builder /build/target/mdd-code-share-1.0.0.jar app.jar
EXPOSE 9090
ENV JAVA_OPTS="-Xms512m -Xmx512m"
ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar app.jar --spring.profiles.active=prod"]
